package hu.diploma.android.threads;

import hu.diploma.android.util.ServiceProviderImpl;
import hu.diploma.common.resource.SmsMmsResource;
import hu.diploma.common.vos.SmsMmsVo;

import java.util.ArrayList;

import org.restlet.resource.ClientResource;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class SmsMmsThread extends Thread {

	public final static int DONE = 1;
	final static int RUNNING = 0;

	Handler mHandler;
	int mState;
	int total;

	public SmsMmsThread(Handler h) {
		mHandler = h;
	}

	@Override
	public void run() {

		mState = SmsMmsThread.RUNNING;

		while (mState == SmsMmsThread.RUNNING) {
			Log.d("DEBUG", "START PeopleThread1");
			ClientResource cr = new ClientResource("http://192.168.1.64:8888/restlet/sms");

			SmsMmsResource resource = cr.wrap(SmsMmsResource.class);

			ArrayList<SmsMmsVo> emailVos = (ArrayList<SmsMmsVo>) ServiceProviderImpl.getInstance().getSmsMmsVos();

			resource.merge(emailVos);

			Bundle b = new Bundle();
			mState = SmsMmsThread.DONE;
			b.putInt("state", SmsMmsThread.DONE);
			Message msg = mHandler.obtainMessage();
			msg.setData(b);
			mHandler.sendMessage(msg);

		}
	}

	public void setState(int state) {
		mState = state;
	}
}